<?php

namespace app\modules\setting\models\yjrwsz;

use yii\helpers\Json;

/**
 * This is the model class for table "{{%etc_content}}".
 *
 * @property int $id
 * @property string $content 预设开头内容
 * @property string $create_at 创建时间
 * @property string $update_at 最后更新时间
 */
class EtcContent extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%etc_content}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['content', 'create_at', 'update_at'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            
            'id' => 'ID',
            
            'content' => '预设开头内容',
            
            'create_at' => '创建时间',
                                    
            'update_at' => '最后更新时间',
        ];
    }


    public function beforeValidate()
    {
        foreach ($this->attributes() as $field){
            if (is_array($this->$field)){
                $this->$field = Json::encode($this->$field);
            }
        }

        return parent::beforeValidate(); // TODO: Change the autogenerated stub
    }

    public function getFirstErrorStr()
    {
        $errors = $this->getErrors();

        if ($errors){
            foreach ($errors as $item){
                return $item[0];
            }
        }

        return "";
    }
}
